<?php
class DBConnection
{
	var $conn;
	
	public function __construct($addr="", $user="", $password="", $db="")
	{
		if($addr && $user && $password)
		{
			$this->getConnection($addr, $user, $password);
			if($db)
			{	
				$this->useDB($db);
			}
		}
	}
	
	public function __destruct()
	{
		if($this->conn)
		{
			mysql_close($this->conn);
		}
	}
	
	public function getConnection($addr, $user, $password)
	{
		$this->conn = mysql_connect($addr, $user, $password);
		return $this->conn;
	}
	
	public function useDB($db)
	{
		mysql_select_db($db, $this->conn);
	}
	
	public function executeQuery($sql)
	{
		if(!$this->conn)
		{
			die("No available connection!");
		}
		mysql_query($sql, $this->conn);
	}
	
	public function close()
	{
		if($this->conn)
		{
			mysql_close($this->conn);
		}
	}
}

?>